﻿using System.Collections.Generic;

namespace ZFramework.Runtime
{
    public class PacketS2C : Packet
    {
        public static int EventId = typeof(PacketS2C).GetHashCode();
        
        public override int Id
        {
            get { return EventId; }
        }
        
        public PacketS2C()
        {
            AllMessages = new List<PacketMessage>();
        }

        public int PacketId
        {
            get;
            private set;
        }

        public List<PacketMessage> AllMessages
        {
            get;
        }

        public void AddMessage(PacketMessage msg)
        {
            AllMessages.Add(msg);
        }

        public static PacketS2C Create(int packetId)
        {
            PacketS2C packetS2C = ReferencePool.Acquire<PacketS2C>();
            packetS2C.PacketId = packetId;
            packetS2C.AllMessages.Clear();
            
            return packetS2C;
        }

        public override void Clear()
        {
            PacketId = 0;
            AllMessages.Clear();
        }
    }
}